<?php
use kartik\grid\GridView;
use yii\helpers\Html;
$this->registerCss(".kv-merged-header{border-bottom:1px solid #eee !important}");
$this->title = '部门列表';
$this->params['breadcrumbs'][] = ['label' => '部门管理', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$gridColumns = [
    ['class' => 'kartik\grid\CheckboxColumn',//多选列
        'rowSelectedClass' => GridView::TYPE_INFO,//通用设置
        'visible'=>true,//不显示，代码也没有
        //'hidden'=>true,//隐藏，代码还有，导出csv等时还存在
        'hiddenFromExport'=>true,//虽然显示，但导出csv时忽略掉
        //'pageSummary'=>'总计',//可以是字符串，当为true时，自动合计
        'mergeHeader'=>true,//合并标题和检索栏
    ],
    ['attribute' => 'id','contentOptions'=>['width'=>'30px']],
    ['attribute' => 'section_name'],
    ['attribute'=>'updated_at','label'=>'最后修改时间','format'=>['date','php:Y-m-d H:i:s']],
    [
        'class' => 'kartik\grid\ActionColumn',//动作列
        'dropdown' => false,
        'vAlign'=>'middle',
        'urlCreator' => function($action, $model, $key, $index) { return 'index.php?r=section/'.$action.'&id='.$key; },
        'viewOptions'=>['title'=>'显示', 'data-toggle'=>'tooltip'],
        'updateOptions'=>['title'=>'更新', 'data-toggle'=>'tooltip'],
        'deleteOptions'=>['title'=>'删除', 'data-toggle'=>'tooltip'],
    ],
];
echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => $gridColumns,
    'containerOptions' => ['style'=>'overflow: auto'], // only set when $responsive = false
    'toolbar' =>  [
        ['content' =>
            Html::a('新增', ['section/create'], ['class' => 'btn btn-success'])
        ],
        '{export}',
        '{toggleData}'
    ],
    'pjax' => true,
    'bordered' => true,
    'striped' => false,
    'condensed' => false,
    'responsive' => true,
    'hover' => true,
    'floatHeader' => true,
    'floatHeaderOptions' => ['scrollingTop' => '23'],
    'showPageSummary' => true,
    'panel' => [
        'heading'=>'<i class="glyphicon glyphicon-book"></i>',//不要了
        'before'=>'<div style="margin-top:8px">{summary}</div>',//放在before中，前面的div主要是想让它好看
        'type' => GridView::TYPE_PRIMARY //设置样式
    ],
    'toggleDataOptions'=>[
        'maxCount' => 200,//当超过200条时，此按钮隐藏，以免数据太多造成加载问题
        'minCount' => 5,//当现有总条数大于此值时,点击不会出现下方提示
        'confirmMsg' => '总共'. number_format($dataProvider->getTotalCount()).'条数据，确定要显示全部？',//点击时的确认
    ],
    'export'=>[
        'target'=>'_blank',//在新标签打开
        'encoding'=>'utf-8',//编码
    ],
        'exportConfig' => [
                GridView::CSV => [],
                GridView::EXCEL => [],
                GridView::JSON => [],
                ]
]);